/*
* SavingsAccount
*
* r3
*
* GNU General Public License v3.0
*/

package com.acme.bankapp.domain.account;

import com.acme.bankapp.exceptions.*;

public class SavingsAccount extends AbstractAccount {
	
	private double balance;

	public SavingsAccount(final double balance) {
		if(balance < 0) {
			throw new IllegalArgumentException();
		}
		
		this.balance = balance;
	}
	
	public void deposit(final double amount) {
		if(amount < 0) {
			throw new IllegalArgumentException();
		}
		
		this.balance += amount;
	}

	public void withdraw(final double amount) throws NotEnoughFundsException {
		if(amount < 0) {
			throw new IllegalArgumentException();
		}
		
		if(this.balance < amount) {
			throw new NotEnoughFundsException(this, amount);
		}
		
		if(this.balance >= amount) {
			this.balance -= amount;
		}
	}
	
	public double getBalance() {
		return this.balance;
	}
	
	public double maximumAmountToWithdraw() {
		return this.balance;
	}
	
	@Override
	public String toString() {
		return "Balance: " + this.balance;
	}
	
	public long decimalValue() {
		return Math.round(this.balance);
	}
}
